package com.sfpay.coreplatform.account.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sfpay.coreplatform.account.common.AccountResponseCode;
import com.sfpay.coreplatform.account.persistence.dao.ITallySerialDao;
import com.sfpay.coreplatform.account.service.ITallySerialService;
import com.sfpay.coreplatform.account.service.exception.AccountServiceException;
import com.sfpay.coreplatform.account.valueobject.dto.TallySerialQuery;
import com.sfpay.coreplatform.account.valueobject.tmo.TallySerial;
import com.sfpay.framework.base.pagination.IPage;
import com.sfpay.framework.base.pagination.impl.Page;

@Service
public class TallySerialServiceImpl implements ITallySerialService {
	
	private static Logger logger = LoggerFactory.getLogger(TallySerialServiceImpl.class);
	
	@Resource
	private ITallySerialDao tallySerialDao;
	
	@Override
	public List<TallySerial> findTallySerial(TallySerialQuery tallySerialQuery)
			throws AccountServiceException {
		
		logger.info("TallySerialServiceImpl_findTallySerial start");
		if(tallySerialQuery == null){
			throw new AccountServiceException(AccountResponseCode.NULL_PARAMETER_ERROR,"parameter is null error");
		}
		
		return tallySerialDao.queryTallySerial(tallySerialQuery);
	}

	@Override
	public IPage<TallySerial> findTallySerialByPage(
			TallySerialQuery tallySerialQuery, int index, int size)
			throws AccountServiceException {
		logger.info("TallySerialServiceImpl_findTallySerialByPage start");
		
		if(tallySerialQuery == null || index == 0 || size == 0){
			throw new AccountServiceException(AccountResponseCode.NULL_PARAMETER_ERROR,"parameter is null error");
		}
		
		Long count = 0L;
		count = tallySerialDao.queryTallySerialCount(tallySerialQuery);
		if(count < 0){
			throw new AccountServiceException(AccountResponseCode.TALLYSERIAL_QUERY_COUNT_ERROR,"tallyserial query count can't be less than 0");
		}
		List<TallySerial> tslist= tallySerialDao.queryTallySerialByPage(tallySerialQuery, index, size);
		
		IPage<TallySerial> page = new Page<TallySerial>(tslist,count,index,size);
		return page;
	}

}
